package com.anti.modular.sys.dict.controller;

import com.anti.commom.annotation.BusinessLog;
import com.anti.commom.annotation.Permission;
import com.anti.commom.api.Result;
import com.anti.commom.enums.LogAnnotionOpTypeEnum;
import com.anti.jdbc.DBUtils;
import com.anti.jdbc.support.page.PageParam;
import com.anti.modular.sys.dict.param.SysDictDataParam;
import com.anti.modular.sys.dict.param.SysDictTypeParam;
import com.anti.modular.sys.dict.service.SysDictTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description TODO
 * @Author anTi
 * @Date 2021-3-5
 */
@RestController
@RequestMapping("/sysDictType")
public class SysDictTypeController {

    @Autowired
    SysDictTypeService sysDictTypeService;


    /**
     * 分页查询系统字典类型
     */
    @GetMapping("page")
    @BusinessLog(title = "系统字典类型_分页查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public Result page(PageParam pageParam,SysDictTypeParam sysDictTypeParam) {
        return Result.data(sysDictTypeService.page(pageParam,sysDictTypeParam));
    }
    /**
     * 查看系统字典类型
     */
    @Permission
    @GetMapping("detail")
    @BusinessLog(title = "系统字典类型_查看", opType = LogAnnotionOpTypeEnum.DETAIL)
    public Result detail(@Validated(SysDictTypeParam.detail.class) SysDictTypeParam sysDictTypeParam) {
        return Result.data(sysDictTypeService.detail(sysDictTypeParam));
    }

    /**
     * 添加系统字典类型
     */
    @Permission
    @PostMapping("add")
    @BusinessLog(title = "系统字典类型_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public Result add(@RequestBody @Validated(SysDictTypeParam.add.class) SysDictTypeParam sysDictTypeParam) {
        sysDictTypeService.add(sysDictTypeParam);
        return Result.success("字典类型增加成功");
    }

    /**
     * 删除系统字典类型
     */
    @PostMapping("delete")
    @BusinessLog(title = "系统字典类型_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public Result delete(@RequestBody @Validated(SysDictTypeParam.delete.class) SysDictTypeParam sysDictTypeParam) {
        sysDictTypeService.delete(sysDictTypeParam);
        return Result.success("字典类型删除成功");
    }

    /**
     * 编辑系统字典类型
     */
    @PostMapping("edit")
    @BusinessLog(title = "系统字典类型_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
    public Result edit(@RequestBody @Validated(SysDictTypeParam.edit.class) SysDictTypeParam sysDictTypeParam) {
        sysDictTypeService.edit(sysDictTypeParam);
        return Result.success("字典类型修改成功");
    }

    /**
     * 修改状态
     */
    @PostMapping("changeStatus")
    @BusinessLog(title = "系统字典类型_修改状态", opType = LogAnnotionOpTypeEnum.CHANGE_STATUS)
    public Result changeStatus(@RequestBody @Validated(SysDictTypeParam.changeStatus.class) SysDictTypeParam sysDictTypeParam) {
        sysDictTypeService.saveChangeStatus(sysDictTypeParam);
        return Result.success("字典类型修改成功");
    }
    /**
     * 系统字典类型与字典值构造的树
     */
    @GetMapping("/tree")
    public Result tree() {
        return Result.data(sysDictTypeService.tree());
    }


    /**
     * 获取字典类型列表
     */
    @GetMapping("/list")
    public Result list(SysDictTypeParam sysDictTypeParam) {
        return Result.data(sysDictTypeService.list(sysDictTypeParam));
    }

    /**
     * 获取字典类型下所有字典，举例，返回格式为：[{code:"M",value:"男"},{code:"F",value:"女"}]
     */
    @GetMapping("/dropDown")
    public Result dropDown(SysDictTypeParam sysDictTypeParam) {
        return  Result.data(sysDictTypeService.dropDown(sysDictTypeParam));
    }

}
